﻿#region Copyright (c) 2010 R. Uittenbosch
/*
* Copyright (C) 2010 R. Uittenbosch
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 
* associated documentation files (the "Software"), to deal in the Software without restriction, including 
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
* copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the 
* following conditions:
* 
* The above copyright notice and this permission notice shall be included in all copies or substantial 
* portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 
* EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#endregion

using System.Drawing;
using System.Runtime.InteropServices;
using System;
namespace TouchUI.System.Mobile.Mvc
{

  /// <summary>
  /// Helperclass to be able to interact with the OS.
  /// </summary>
  public sealed class Win32Helper
  {
    #region Structs
    public struct RECT
    {
      public int left;
      public int top;
      public int right;
      public int bottom;
    }
    public struct TRIVERTEX
    {
      public int x;
      public int y;
      public ushort Red;
      public ushort Green;
      public ushort Blue;
      public ushort Alpha;
      public TRIVERTEX(int x, int y, Color color)
        : this(x, y, color.R, color.G, color.B, color.A)
      {
      }
      public TRIVERTEX(
          int x, int y,
          ushort red, ushort green, ushort blue,
          ushort alpha)
      {
        this.x = x;
        this.y = y;
        this.Red = (ushort)(red << 8);
        this.Green = (ushort)(green << 8);
        this.Blue = (ushort)(blue << 8);
        this.Alpha = (ushort)(alpha << 8);
      }
    }
    public struct GRADIENT_RECT
    {
      public uint UpperLeft;
      public uint LowerRight;
      public GRADIENT_RECT(uint ul, uint lr)
      {
        this.UpperLeft = ul;
        this.LowerRight = lr;
      }
    }


    #endregion

    #region DllImports

    [DllImport("coredll")] 
    public static extern IntPtr SelectObject(
        IntPtr hDC, 
        IntPtr hObject);

    [DllImport("coredll.dll")]
    public static extern int DrawText(
        IntPtr hdc, 
        string lpStr, 
        int nCount, 
        ref RECT lpRect, 
        int wFormat); 

    [DllImport("coredll.dll", SetLastError = true, EntryPoint = "GradientFill")]
    public extern static bool GradientFill(
        IntPtr hdc,
        TRIVERTEX[] pVertex,
        uint dwNumVertex,
        GRADIENT_RECT[] pMesh,
        uint dwNumMesh,
        uint dwMode);
    
    #endregion

    #region Constants
    public const int GRADIENT_FILL_RECT_H = 0x00000000;
    public const int GRADIENT_FILL_RECT_V = 0x00000001;
    public static int DT_CALCRECT = 0x00000400;
    public static int DT_WORDBREAK = 0x00000010;
    #endregion
  }
}
